package net.grzechocinski.pages;

import net.grzechocinski.wordcounter.KMP.WordObject;
import net.grzechocinski.wordcounter.core.WordCounter;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.PropertyModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Mateusz
 * @since 2010-05-09
 */
public class ResultsPage extends WebPage {

	public ResultsPage(PageParameters parameters) {

		List<WordObject>  words = WordCounter.analyze(parameters.getString("textToAnalyze"));

		ListView wordsListView = new ListView("words", words) {
			protected void populateItem(ListItem item) {
				final WordObject wo = (WordObject) item.getModelObject();
				item.add(new Label("token", wo.getWord()));
				item.add(new Label("alone", Integer.toString(wo.getAloneCounter())));
				item.add(new Label("inOther", Integer.toString(wo.getInOtherCounter())));
			}
		};

		add(wordsListView);
	}
}
